package com.ghy.text;

import com.ghy.entity.EbNews;
import com.ghy.mapper.NewsMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:xml/spring-dao.xml")
public class MapperTest {
    @Autowired
    NewsMapper newsMapper;

    @Test
    public void testNewsPage(){
        int page =2;//查询第1页
        int pageSize= 3;//每页3条
        //alt+Enter
        List<EbNews> news = newsMapper.findByPage((page - 1) * pageSize, pageSize);
        System.out.println(news);
    }

    @Test
    public void testNewsSave(){
        EbNews enNews = new EbNews();
        enNews.setEnTitle("今天心情正好");
        enNews.setEnContent("又遇到bug");
        int result = newsMapper.save(enNews);
        System.out.println("result-:"+result);
    }

    @Test
    public void testNewsDelete(){
        int result = newsMapper.remove(663);
        System.out.println("result:"+result);
    }
    @Test
    public void testNewsUpdate(){
        EbNews enNews = new EbNews();
        enNews.setEnId(662);
        enNews.setEnTitle("今天心情正好");
        enNews.setEnContent("又遇到bug");
        //调用更新的方法
        int result = newsMapper.updateByPrimaryKey(enNews);
        System.out.println("result:"+result);
    }
    @Test
    public void testGetMaxPage(){
        Integer maxPage = newsMapper.getMaxPage(4);
        System.out.println("maxPage="+maxPage);
    }

    @Test
    public void testSelectOne(){
        System.out.println(newsMapper.selectOne(597) );
    }
}
